package com.rhzy.wnhc.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rhzy.wnhc.entity.*;
import com.rhzy.wnhc.service.TJobWishService;
import com.rhzy.wnhc.service.TPersonService;
import com.rhzy.wnhc.util.AjaxResult;
import com.rhzy.wnhc.util.CheckIdcardIsLegal;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Authorization;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wen
 * @since 2020-02-18
 */
@Api(tags = "个人用工信息")
@RestController
@RequestMapping("/admin/person")
public class TPersonController {

    @Autowired
    TPersonService service;
    @Autowired
    TJobWishService jobWishService;
    @ApiOperation(value = "用工信息分页查询", tags = {"个人用工信息",})
    @RequestMapping(value = "/pageList", method = RequestMethod.POST)
    public AjaxResult pageList(@RequestBody PageParam pageParam)
    {
        LambdaQueryWrapper<TPerson> queryWrapper =  new LambdaQueryWrapper<>();
        queryWrapper.orderByDesc(TPerson::getId);
        queryWrapper.likeLeft(!StringUtils.isEmpty(pageParam.getAreaInfo()),TPerson::getAddressCode,pageParam.getAreaInfo()     );
        queryWrapper.like(!StringUtils.isEmpty(pageParam.getIdCard()),TPerson::getIdCard,pageParam.getIdCard());
        queryWrapper.like(!StringUtils.isEmpty(pageParam.getName()),TPerson::getName,pageParam.getName());
        queryWrapper.like(!StringUtils.isEmpty(pageParam.getPhone()),TPerson::getPhone,pageParam.getPhone());
        Page<TPerson> page = new Page<>(pageParam.getPageIndex(),pageParam.getPageSize());  // 查询第1页，每页返回5条
        IPage<TPerson> iPage = service.page(page,queryWrapper);

        return AjaxResult.addSuccess(iPage,"查询成功！");
    }

    @ApiOperation(value = "乘车人员信息分页查询", tags = {"个人用工信息",})
    @RequestMapping(value = "/jobWishList", method = RequestMethod.POST)
    public AjaxResult jobWishList(@RequestBody PageParam pageParam)
    {
        LambdaQueryWrapper<TJobWish> queryWrapper =  new LambdaQueryWrapper<>();
        queryWrapper.orderByDesc(TJobWish::getId);
        queryWrapper.like(!StringUtils.isEmpty(pageParam.getName()),TJobWish::getName,pageParam.getName());
        queryWrapper.like(!StringUtils.isEmpty(pageParam.getPhone()),TJobWish::getPhone,pageParam.getPhone());
        Page<TJobWish> page = new Page<>(pageParam.getPageIndex(),pageParam.getPageSize());  // 查询第1页，每页返回5条
        IPage<TJobWish> iPage = jobWishService.page(page,queryWrapper);

        return AjaxResult.addSuccess(iPage,"查询成功！");
    }
}
